]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool: Add quick settings template
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 14 Aug 2023 15:51:35 +0000 (17:51 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 20 Aug 2023 00:06:24 +0000 (02:06 +0200)
Extending quick settings has become popular enough to justify a
template.

Add a small indicator+quick-item example that exercises the
previously added API.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2894>

po/POTFILES.in
po/POTFILES.skip
subprojects/extensions-tool/src/gnome-extensions-tool.gresource.xml
subprojects/extensions-tool/src/templates/meson.build
subprojects/extensions-tool/src/templates/quick-settings.desktop.in [new file with mode: 0644]
subprojects/extensions-tool/src/templates/quick-settings/extension.js [new file with mode: 0644]
subprojects/extensions-tool/src/templates/quick-settings/stylesheet.css [new file with mode: 0644]

index 74a521202207a023c593bb9f90c46bdb8b10e711..93ad531a312035a7260e810aef1451beb7913328 100644 (file)
@@ -107,5 +107,6 @@ subprojects/extensions-tool/src/command-uninstall.c
 subprojects/extensions-tool/src/main.c
 subprojects/extensions-tool/src/templates/00-plain.desktop.in
 subprojects/extensions-tool/src/templates/indicator.desktop.in
+subprojects/extensions-tool/src/templates/quick-settings.desktop.in
 # Please do not remove this file from POTFILES.in. Run "git submodule init && git submodule update" to get it.
 subprojects/gvc/gvc-mixer-control.c
index 0c8451d648520da9a82b4b92dbac78277a306ed4..36fe39be55bf750be1bd587cfe124ee62eabe4af 100644 (file)
@@ -2,3 +2,4 @@ data/org.gnome.Shell@wayland.service.in
 data/org.gnome.Shell@x11.service.in
 js/ui/init.js
 subprojects/extensions-tool/src/templates/indicator/extension.js
+subprojects/extensions-tool/src/templates/quick-settings/extension.js
index 0db87c3c2c490545f2065263d7d283aa9f36afa1..4a64c61956f9e907c8f8082bf40dfac547c1ce70 100644 (file)
@@ -7,5 +7,8 @@
     <file>templates/indicator/stylesheet.css</file>
     <file>templates/plain/extension.js</file>
     <file>templates/plain/stylesheet.css</file>
+    <file>templates/quick-settings.desktop</file>
+    <file>templates/quick-settings/extension.js</file>
+    <file>templates/quick-settings/stylesheet.css</file>
   </gresource>
 </gresources>
index d693bfaddb67067b0914ec247b457f7071e7cc9c..8c0079ecb67d7993c15729366bd7c78fd3dfc73b 100644 (file)
@@ -1,6 +1,7 @@
 template_metas = [
   '00-plain.desktop',
   'indicator.desktop',
+  'quick-settings.desktop',
 ]
 template_deps = []
 foreach template : template_metas
diff --git a/subprojects/extensions-tool/src/templates/quick-settings.desktop.in b/subprojects/extensions-tool/src/templates/quick-settings.desktop.in
new file mode 100644 (file)
index 0000000..e2fc3d8
--- /dev/null
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Type=Application
+Name=Quick Settings Item
+Comment=Add an item to quick settings
+Path=quick-settings
diff --git a/subprojects/extensions-tool/src/templates/quick-settings/extension.js b/subprojects/extensions-tool/src/templates/quick-settings/extension.js
new file mode 100644 (file)
index 0000000..a3faf65
--- /dev/null
@@ -0,0 +1,62 @@
+/* extension.js
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import GObject from 'gi://GObject';
+
+import * as Main from 'resource:///org/gnome/shell/ui/main.js';
+
+import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
+import {QuickToggle, SystemIndicator} from 'resource:///org/gnome/shell/ui/quickSettings.js';
+
+const ExampleToggle = GObject.registerClass(
+class ExampleToggle extends QuickToggle {
+    constructor() {
+        super({
+            title: _('Smile'),
+            iconName: 'face-smile-symbolic',
+            toggleMode: true,
+        });
+    }
+});
+
+const ExampleIndicator = GObject.registerClass(
+class ExampleIndicator extends SystemIndicator {
+    constructor() {
+        super();
+
+        this._indicator = this._addIndicator();
+        this._indicator.iconName = 'face-smile-symbolic';
+
+        const toggle = new ExampleToggle();
+        toggle.bind_property('checked',
+            this._indicator, 'visible',
+            GObject.BindingFlags.SYNC_CREATE);
+        this.quickSettingsItems.push(toggle);
+    }
+});
+
+export default class QuickSettingsExampleExtension extends Extension {
+    enable() {
+        this._indicator = new ExampleIndicator();
+        Main.panel.statusArea.quickSettings.addExternalIndicator(this._indicator);
+    }
+
+    disable() {
+        this._indicator.quickSettingsItems.forEach(item => item.destroy());
+        this._indicator.destroy();
+    }
+}
diff --git a/subprojects/extensions-tool/src/templates/quick-settings/stylesheet.css b/subprojects/extensions-tool/src/templates/quick-settings/stylesheet.css
new file mode 100644 (file)
index 0000000..37b93f2
--- /dev/null
@@ -0,0 +1 @@
+/* Add your custom extension styling here */